package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Companybank;
import edu.hwadee.service.CompanybankService;

public class CompanybankServiceImpl extends BasicServiceImpl implements CompanybankService {

	@Override
	public boolean save(Companybank companybank) {
		try {
			getCompanybankDAO().save(companybank);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Companybank companybank) {
		try {
			getCompanybankDAO().delete(companybank);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Companybank> search(Companybank companybank) {
		try {
			return (List<Companybank>)getCompanybankDAO().findByExample(companybank);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Companybank searchById(Integer companybankId) {
		try {
			return getCompanybankDAO().findById(companybankId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Companybank companybank) {
		try {
			if(searchById(companybank.getCompanyBankId()) != null) {
				getCompanybankDAO().merge(companybank);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Companybank> showAll() {
		try {
			return (List<Companybank>)getCompanybankDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
